package cn.readjava.dao;

import cn.readjava.bean.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Set;

public interface PermissionDao extends JpaRepository<Permission, Long> {

    @Query(value = "SELECT p.permission_name FROM user u LEFT JOIN user_role ur ON u.user_id = ur.u_id LEFT JOIN role r ON ur.r_id = r.role_id LEFT JOIN role_permission rp ON rp.r_id = r.role_id LEFT JOIN permission p ON p.permission_id = rp.p_id WHERE u.user_id = ?1", nativeQuery = true)
    Set<String> findAllPermission(long userId);
}